#define LO_BYTE	1
#define HI_BYTE	0

//uns16 temperature;
uns8  temperature;

// Converted data is of the form 0bxxxxxxxx xx000000
// Maintain filtered value in the form 0bxxxxxxxx xxxxxx00
//   as this will allow filtering to be done without rounding errors.
// After filtering, data is rounded 
//   If bit 0b00000000 000000X0 is set then add 0b00000000 00000100

#if 0
void int_atod( void )
{
   switch( channel )
   {
      case( 0 ):
         voltage = ( (unsigned long)ADRESH<<8 ) | ADRESL;
         ADCON0 = T_MON_CONV;
         channel = 1;
         break;

      case( 1 ):
         temperature = ( (unsigned long)ADRESH<<8 ) | ADRESL;
         ADCON0 = HS_MON_CONV;
         channel = 2;
         break;

      case( 2 ):
         hs_current = ( (unsigned long)ADRESH<<8 ) | ADRESL;
         ADCON0 = SP_MON_CONV;
         channel = 3;
         break;

      case( 3 ):
         sp_current = ( (unsigned long)ADRESH<<8 ) | ADRESL;
         ADCON0 = HB_MON_CONV;
         channel = 4;
         break;

      case( 4 ):
         hb_current = ( (unsigned long)ADRESH<<8 ) | ADRESL;

      default:
         ADCON0 = V_MON_CONV;
         channel = 0;
   }
}
#endif

#if 0
void int_atod_2( void )
{
	unsigned long oldVal, newVal, accum;

	oldVal = analogData[channel];
	newVal = ( (unsigned long)ADRESH<<8 ) | ADRESL;

	oldVal >>= 1;
	accum = oldVal;

	oldVal >>= 1;
	accum += oldVal;

	oldVal >>= 1;
	accum += oldVal;

	newVal >>= 3;
	accum += newVal;

   analogData[channel] = accum;

	channel++;
	if( channel > 4 )
		channel = 0;

	ADCON0 = analogConv[channel];
}   
#endif
void getTemp( void )
{
#if 0
   // Filter
   // NewTmp = OldTemp * 3/4  +  NewTemp * 1/4
   uns16 oldTemp;

   oldTemp = temperature >> 1;

   temperature.high8 = ADRESH;
   temperature.low8  = ADRESL;

   temperature >>= 2;
	temperature += oldTemp;
   oldTemp >>= 1;
	temperature += oldTemp;

	if( temperature.1 )
		temperature += 4;

	temperature.low8 &= 0b11111100;
#endif

#if 0
   // Filter
   // NewTmp = OldTemp * 3/4  +  NewTemp * 1/4
   uns16 oldTemp;

   oldTemp = temperature >> 2;
	if( temperature.1 )
		oldTemp++;

   temperature.high8 = ADRESH;
   temperature.low8  = ADRESL;

   temperature >>= 2;
	temperature += oldTemp;
	temperature += oldTemp;
	temperature += oldTemp;
#endif


#if 0
   // Filter
   // NewTmp = (OldTemp*3 + NewTemp )/4
   uns16 oldTemp;

	oldTemp = temperature<<1;
	temperature += oldTemp;
	temperature += ADRESL;
	temperature.high8 += ADRESH;

	if( temperature.1 )
		temperature+=4;
	temperature >>= 2;
#endif

#if 0
   // Filter
   // NewTmp = (OldTemp + NewTemp )/2
	
	temperature += ADRESL;
	temperature.high8 += ADRESH;

	if( temperature.0 )
		temperature += 2;
	temperature >>= 1;
#endif

#if 0
   // Filter
   // NewTmp = (OldTemp + NewTemp )/2
	temperature.low8 += ADRESH;
	if( temperature.0 )
		temperature += 2;
	temperature >>= 1;
#endif

#if 1
   // Filter
   // NewTmp = (OldTemp + NewTemp )/2
	temperature += ADRESH;
	temperature >>= 1;
   temperature.7 = Carry;
#endif



   ADCON0 = T_MON_CONV;
}